#include "file_manager.h"
#include "lru_list.h"


int LRUList::update(Page* page)
{
	if(page->lruPos != lp.end()){
		lp.erase(page->lruPos);
	}

	lp.push_front(page);
	page->lruPos = lp.begin();

	return 0;
}

int LRUList::remove(Page* page)
{
	if(page->lruPos != lp.end())
	{
		lp.erase(page->lruPos);
		page->lruPos = lp.end();
	}

	return 0;
}

int LRUList::getLastPages(int c,vector<Page*>& vp)
{
	int i = 0;

	while( c > i){
		++i;
		if(!lp.empty()){
			Page* p = lp.back();
			p->lruPos = lp.end();
			vp.push_back(p);
			
			lp.pop_back();
		}
	}

	return 0;
}
